<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input id="name" type="text">
    <button id="submit-btn">Submit</button>
    <script>
        var btn = document.getElementById('submit-btn');
        btn.onclick = function() {
            let text = document.getElementById('name');
            console.log(text.value);
        }
        var text = document.getElementById('name');
        text.addEventListener('keydown', (event) => {
            if (event.keyCode === 27) {
                text.value = '';
            }
            if (event.keyCode === 13) {
                console.log(text.value);
            }
        })
    </script>
</body>

</html>